'use strict';

angular.module('App').controller('uploadTestController',
    ['$scope', '$stateParams', 'BaseModule', 'BaseFunction', '$location', 'Authentication', 'FileUploader',
    function($scope, $stateParams, BaseModule, BaseFunction, $location, Authentication, FileUploader) {
        var uploader = $scope.uploader = new FileUploader({url: '/api/uploadFile'}); 
         // FILTERS 
         uploader.filters.push({name: 'customFilter', 
            //1，客户端上传文件时触发，每上传一个触发一次，限制上传的文件个数
             fn: function(fileItem, options) { 
                 return this.queue.length < 10; 
             } 
         });  
 
         // CALLBACKS 
         //客户端上传失败时触发
         uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/, filter, options) { 
             console.info('onWhenAddingFileFailed', item, filter, options); 
         }; 
         //2，客户端上传完毕时触发
         uploader.onAfterAddingFile = function(fileItem) {
            //在此可添加其他上传参数
            fileItem.formData.push({"FileName": 4444444});
            fileItem.formData.push({"OldPath": 4444444});
            console.info('onAfterAddingFile', fileItem); 
         }; 
         //3，客户端所有文件上传完毕时触发
         uploader.onAfterAddingAll = function(addedFileItems) { 
             console.info('onAfterAddingAll', addedFileItems); 
         }; 
         //（1）上传给服务器之前触发
         uploader.onBeforeUploadItem = function(item) { 
             console.info('onBeforeUploadItem', item); 
         }; 
         //（2）单个文件上传给服务器时，进度发生变化触发
         uploader.onProgressItem = function(fileItem, progress) { 
             console.info('onProgressItem', fileItem, progress); 
         };
         //（3）全部文件上传给服务器时，总进度发生变化触发
         uploader.onProgressAll = function(progress) { 
             console.info('onProgressAll', progress); 
         }; 
         //(4)单个文件上传，成功时触发
         uploader.onSuccessItem = function(fileItem, response, status, headers) { 
             console.info('onSuccessItem', fileItem, response, status, headers); 
         }; 
         //(4)单个文件上传服务器，失败时触发
         uploader.onErrorItem = function(fileItem, response, status, headers) { 
             console.info('onErrorItem', fileItem, response, status, headers); 
         };
         //单个文件上传，取消时触发
         uploader.onCancelItem = function(fileItem, response, status, headers) { 
             console.info('onCancelItem', fileItem, response, status, headers); 
         }; 
         //(5)单个文件上传完成时触发，包括上传失败
         uploader.onCompleteItem = function(fileItem, response, status, headers) { 
             console.info('onCompleteItem', fileItem, response, status, headers); 
         }; 
         //(6)所有文件上传完成时触发，包括上传失败
         uploader.onCompleteAll = function() { 
             console.info('onCompleteAll'); 
         }; 
 
         console.info('uploader', uploader);
    }
]);